package com.ruoyi.merchant.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitOrderConfig {
//    延时队列 死信交换机
    @Bean
    public Exchange ttlExchange() {
        return ExchangeBuilder.topicExchange("order_ttl_exchange").durable(true).build();
    }
    //    延时队列 死信队列
    @Bean
    public Queue ttlQueue() {
        return QueueBuilder.durable("order_ttl_queue").deadLetterExchange("order_normal_exchange").deadLetterRoutingKey("normal.cancel").ttl(2*60*60 * 1000).build();
    }
    // 绑定队列和交换机
    @Bean
    public Binding bindingQueue1() {

        return BindingBuilder.bind(ttlQueue()).to(ttlExchange()).with("order.#").noargs();
    }

    @Bean
    public Exchange normalExchange() {
        return ExchangeBuilder.topicExchange("order_normal_exchange").durable(true).build();
    }
    //    延时队列 死信队列
    @Bean
    public Queue normalQueue() {
        return QueueBuilder.durable("order_normal_queue").build();
    }
    // 绑定队列和交换机
    @Bean
    public Binding bindingnormalQueue1() {

        return BindingBuilder.bind(normalQueue()).to(normalExchange()).with("normal.#").noargs();
    }
}
